package com.rederxu.tools;

import com.rederxu.farmer.R;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

public class Dialog {

	public static void showMessageDialog(final Context mContext,
			String title,String message,
			String positiveText,String negativeText,
			final OnClickListener listener){
		AlertDialog.Builder builder = new Builder(mContext);
		final AlertDialog mDialog = builder.create();
		Window window = mDialog.getWindow();
		mDialog.show();
		window.setGravity(Gravity.CENTER);
		mDialog.setCancelable(true);
		window.setContentView(R.layout.dialog_farmer);
		TextView tvTitle = (TextView) window.findViewById(R.id.title_dialog_farmer);
		TextView tvMessage = (TextView) window.findViewById(R.id.message_dialog_farmer);
		TextView tvPositive = (TextView) window.findViewById(R.id.positive_dialog_farmer);
		TextView tvNegative = (TextView) window.findViewById(R.id.negative_dialog_farmer);
		if(title == null){
			title = "null";
		}
		if(message == null){
			message = "null";
		}
		if(positiveText == null){
			positiveText = "null";
		}
		if(negativeText == null){
			negativeText = "null";
		}
		tvTitle.setText(title);
		tvMessage.setText(message);
		tvPositive.setText(positiveText);
		tvNegative.setText(negativeText);
		tvPositive.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				mDialog.dismiss();
				if(listener != null){
					listener.onClick(mDialog, DialogInterface.BUTTON_POSITIVE);
				}
			}
		});
		tvNegative.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				mDialog.dismiss();
				if(listener != null){
					listener.onClick(mDialog, DialogInterface.BUTTON_NEGATIVE);
				}
			}
		});
	}
}
